/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TelaAddDetalhesDpto.java
 *
 * Created on Dec 10, 2011, 9:19:13 PM
 */
package com.googlecode.view;

import com.googlecode.entity.Departamento;
import com.googlecode.services.Facade;
import java.awt.Container;
import java.awt.FlowLayout;
import java.util.List;
import javax.swing.DefaultListModel;

/**
 *
 * @author italo
 */
public class TelaAddDetalhesDpto extends javax.swing.JFrame {

    /** Creates new form TelaAddDetalhesDpto */
    public TelaAddDetalhesDpto() {
        initComponents();
        this.f = new Facade().getInstance();
        gerarListDpto(this.f.getListDepartamento());
        gerarBoxDpto(this.f.getListDepartamento());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        listDepartamentos = new javax.swing.JList();
        boxDpto = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jScrollPane1.setViewportView(listDepartamentos);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(boxDpto, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING))
                .addContainerGap(130, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(boxDpto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(118, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
   
    
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TelaAddDetalhesDpto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TelaAddDetalhesDpto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TelaAddDetalhesDpto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TelaAddDetalhesDpto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new TelaAddDetalhesDpto().setVisible(true);
            }
        });
    }
    Facade f;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox boxDpto;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JList listDepartamentos;
    // End of variables declaration//GEN-END:variables

    private void gerarListDpto(List <Departamento>lista) {
        Container c = getContentPane();
        c.setLayout(new FlowLayout(FlowLayout.LEFT));
        
        for (Departamento d : lista){
            if (d.getNome().length() != 0){
                ((DefaultListModel)(this.listDepartamentos.getModel())).addElement(d.getNome());
                
            }
        }
    }
    
    private void gerarBoxDpto(List<Departamento> departamentos){
        for (Departamento d : departamentos){
            
            this.boxDpto.addItem(d);
        
        }
    }
}
